package com.nc.cloud.admin.rest;

import com.nc.cloud.common.msg.TableResultResponse;
import com.nc.cloud.common.rest.BaseController;
import com.nc.cloud.admin.biz.CompanyBiz;
import com.nc.cloud.admin.entity.Company;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Controller
@RequestMapping("company")
public class CompanyController extends BaseController<CompanyBiz, Company> {

    @Autowired
    private CompanyBiz companyBiz;


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public TableResultResponse<Company> page(@RequestParam(defaultValue = "10") int limit, @RequestParam(defaultValue = "1") int offset, @RequestParam(defaultValue = "") String cpname) {
        Example example = new Example(Company.class);
        Example.Criteria criteria = example.createCriteria();

        if (StringUtils.isNotBlank(cpname)) {
            criteria.andLike("cpname", "%" + cpname + "%");
        }
        List<Company> elements = companyBiz.selectByExample(example);
        return new TableResultResponse<Company>(elements.size(), elements);
    }


}